package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.CaseComplaint;
import com.ktgj.customer.service.ICaseComplaintService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 投诉工单Controller
 * 
 * @author ruoyi
 * @date 2022-05-27
 */
@RestController
@RequestMapping("/complaint")
public class CaseComplaintController extends BaseController
{
    @Autowired
    private ICaseComplaintService caseComplaintService;

    /**
     * 查询投诉工单列表
     */
    @PreAuthorize(hasPermi = "system:complaint:list")
    @GetMapping("/list")
    public TableDataInfo list(CaseComplaint caseComplaint)
    {
        startPage();
        List<CaseComplaint> list = caseComplaintService.selectCaseComplaintList(caseComplaint);
        return getDataTable(list);
    }

    /**
     * 导出投诉工单列表
     */
    @PreAuthorize(hasPermi = "system:complaint:export")
    @Log(title = "投诉工单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CaseComplaint caseComplaint) throws IOException
    {
        List<CaseComplaint> list = caseComplaintService.selectCaseComplaintList(caseComplaint);
        ExcelUtil<CaseComplaint> util = new ExcelUtil<CaseComplaint>(CaseComplaint.class);
        util.exportExcel(response, list, "投诉工单数据");
    }

    /**
     * 获取投诉工单详细信息
     */
//    @PreAuthorize(hasPermi = "system:complaint:query")
//    @GetMapping(value = "/{caseComplaintId}")
    @PostMapping("/complaintById")
    public AjaxResult getInfo(@RequestBody Map<String, Long> map)
    {
        Long complaintId =  Long.valueOf(map.get("complaintId"));
        return AjaxResult.success(caseComplaintService.selectCaseComplaintById(complaintId));
    }

    /**
     * 新增投诉工单
     */
    @PreAuthorize(hasPermi = "system:complaint:add")
    @Log(title = "投诉工单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CaseComplaint caseComplaint)
    {
        return toAjax(caseComplaintService.insertCaseComplaint(caseComplaint));
    }

    /**
     * 修改投诉工单
     */
//    @PreAuthorize(hasPermi = "system:complaint:edit")
//    @Log(title = "投诉工单", businessType = BusinessType.UPDATE)
    @PostMapping("/complaintEdit")
    public AjaxResult edit(@RequestBody CaseComplaint caseComplaint)
    {
        return toAjax(caseComplaintService.updateCaseComplaint(caseComplaint));
    }

    /**
     * 删除投诉工单
     */
    @PreAuthorize(hasPermi = "system:complaint:remove")
    @Log(title = "投诉工单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{caseComplaintIds}")
    public AjaxResult remove(@PathVariable Long[] caseComplaintIds)
    {
        return toAjax(caseComplaintService.deleteCaseComplaintByIds(caseComplaintIds));
    }
}
